//
//  MainViewController.swift
//  Weibo
//
//  Created by 周先生 on 15/11/8.
//  Copyright © 2015年 周先生. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

   @objc private func composeDidClick() {
    let compose = ComposeViewController()
    let nav = UINavigationController(rootViewController: compose)
    presentViewController(nav, animated: true, completion: nil)

    }
    override func viewDidLoad() {
        super.viewDidLoad()

        //由于tabbar只读 不能直接进行操作 如果要修改 需要使用KVC
        let mainTabbar = MainTabBar()
        setValue(mainTabbar, forKey: "tabBar")
        //添加子视图控制器
        addChildViewControllers()
        //设置点击事件
        mainTabbar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
    }
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    
    
    }
    
    //重载
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        //设置颜色
//        self.tabBar.tintColor = UIColor.orangeColor()
        //实例化导航视图控制器
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        //添加
        addChildViewController(nav)
    }
}
